package com.tjetc.service.impl;

import com.tjetc.domain.CustomerMessage;
import com.tjetc.mapper.CustomerMapper;
import com.tjetc.mapper.MessageMapper;
import com.tjetc.service.MessageService;
import com.tjetc.utils.Db;
import com.tjetc.vo.Result;

public class MessageServiceImpl implements MessageService {
    private MessageMapper messageMapper= Db.getMapper(MessageMapper.class);
    private Result result=new Result();
    public CustomerMessage selectById(int id){
        return messageMapper.selectById(id);
    }
    @Override
    public Result register(CustomerMessage customerMessage) {
        CustomerMessage message=selectById(customerMessage.getCustomer_id());
        if (message==null){
            int rows=messageMapper.insert(customerMessage);
            if (rows==1){
                return new Result(200,"添加成功",null);
            }
        }
        return new Result(200,"添加失败",null);
    }

    @Override
    public Result update(CustomerMessage customerMessage) {
        CustomerMessage message=selectById(customerMessage.getCustomer_id());
        if (message!=null){
            int rows=messageMapper.update(customerMessage);
            if (rows==1){
                return new Result(200,"修改成功",null);
            }
        }
        return new Result(200,"修改失败",null);
    }

    @Override
    public Result findById(Integer customerId) {
        CustomerMessage customerMessage = messageMapper.selectById(customerId);
        if (customerMessage!=null){
            return result.setCode(200);
        }
        return result.setCode(500);
    }

    @Override
    public Result getMessageByCustomerId(Integer customerId) {
        CustomerMessage customerMessage=messageMapper.getMessageByCustomerId(customerId);
        if (customerMessage!=null){
            return new Result(200,null,customerMessage);
        }else {
            return new Result(500,null,null);
        }
    }

    @Override
    public Result getMessageByDriving(String drivingLicense) {
        CustomerMessage customerMessage=messageMapper.getMessageByDriving(drivingLicense);
        if (customerMessage!=null){
            return new Result(200,null,null);
        }else {
            return new Result(500,null,null);
        }
    }

    @Override
    public Result getMessageByPhone(String phone) {
        CustomerMessage customerMessage=messageMapper.getMessageByPhone(phone);
        if (customerMessage!=null){
            return new Result(200,null,null);
        }else {
            return new Result(500,null,null);
        }
    }
}
